import {AxiosRequestConfig} from "./types/index";
import {tranformResponse, transformRequest} from "./helpers/data";
import {processHeaders} from "./helpers/headers";

const defaults: AxiosRequestConfig = {
    method: 'GET',
    timeout: 0,
    headers: {
      common: {
          Accept: 'application/json, text/json, */*'
      }
    },

    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',

    transformRequest: [
        function (data: any, headers: any):any{
            processHeaders(headers, data)
            return transformRequest(data)
        }
    ],
    transformResponse: [
        function (data: any):any{
            return tranformResponse(data)
        }
    ],

    validateStatus(status: number): boolean{
        return status >= 200 && status < 300
    }
}

const methodsNoData = ['delete', 'get', 'post']
methodsNoData.forEach(method=>{
    defaults.headers[method] = {}
})

const methodsWidthData = ['post', 'put', 'patch']
methodsWidthData.forEach(method=>{
    defaults.headers[method] = {
        "Content-Type": 'application/x-www-form-urlencode'
    }
})

export default defaults










